﻿@using NewLife;
@using NewLife.Cube
@using XCode;
@using XCode.Configuration;
@{
    var pair = (ValueTuple<IEntity, DataField>)Model;
    var entity = pair.Item1;
    var field = pair.Item2;

    var err = 0;
    if (ViewData.ModelState.TryGetValue(field.Name, out var st) && st != null) { err = st.Errors.Count; }

    var des = field.Description.TrimStart(field.DisplayName).TrimStart(",", ".", "，", "。");
}
<label class="control-label col-sm-3 col-md-2 col-lg-1">@field.DisplayName</label>
@if (err > 0)
{
    <span class="col-sm-9 alert alert-danger">
        @Html.ValidationMessage(field.Name)
    </span>
}
else if (!des.IsNullOrEmpty())
{
    <span class="col-sm-9"><span class="middle">@des</span></span>
}
<div class="input-group col-sm-11 col-md-offset-1">
    @if (field.Readonly)
    {
        var row = (Int32)Math.Round(field.Length / 100d);
        if (row < 3) row = 3;
        @*<label class="form-control">@entity[field.Name]</label>*@
        <textarea class="form-control" id="@field.Name" rows="@row" readonly>@entity[field.Name]</textarea>
    }
    else
    {
        @*@Html.ForString(field.Name, (String)entity[field.Name], field.Length)*@
        @await Html.PartialAsync("_Form_String", new ItemModel(field.Name, entity[field.Name], field.Type) { Length = field.Length })
    }
</div>